
import React, { Component } from 'react';
import { connect } from 'dva';
import { message, Modal, Pagination, Popconfirm, Button } from 'antd';
import styles from './Users.css';
import moment from 'moment';
import Factory from '../factory';
import * as datetime from '../../utils/datetime'
import dataEditCreate from '../addons/DataEdit'
import dataTableCreate from '../addons/DataTable'
import * as menuService from '../../services/menus'
import * as com from '../../utils/common';
import YJRDS from './YJRDS'
const daoName = "QDTYXM";
const ButtonGroup = Button.Group;
const columns = [
    { title: '归属类别', width: 170, sorter: true, dataIndex: 'Gslb', key: 'Gslb', dispaly: true, filter: true },
    { title: '客户账号', width: 200, sorter: true, dataIndex: 'Khzh', key: 'Khzh', dispaly: true, filter: true },
    { title: '合同编号', width: 150, sorter: true, dataIndex: 'Htbh', key: 'Htbh', dispaly: true, filter: true },
    { title: '合同名称', width: 380, sorter: true, dataIndex: 'Htmc', key: 'Htmc', dispaly: true, filter: true },
    { title: '理财产品代码', width: 170, sorter: true, dataIndex: 'Lccpdm', key: 'Lccpdm', dispaly: true, filter: true },
    { title: '理财产品名称', width: 300, sorter: true, dataIndex: 'Lccpmc', key: 'Lccpmc', dispaly: true, filter: true },
    { title: '交易对手开户行', width: 260, sorter: true, dataIndex: 'Jydskhx', key: 'Jydskhx', dispaly: true, filter: true },
    { title: '交易对手开户账号', width: 230, sorter: true, dataIndex: 'Jydskhzh', key: 'Jydskhzh', dispaly: true, filter: true },
    { title: '交易对手开户名称', width: 320, sorter: true, dataIndex: 'Jydskhmc', key: 'Jydskhmc', dispaly: true, filter: true },
    { title: '交易对手大额支付系统行号', width: 170, sorter: true, dataIndex: 'Jydsdezf', key: 'Jydsdezf', dispaly: true, filter: true },
    { title: '客户经理', width: 170, sorter: true, dataIndex: 'Khjl', key: 'Khjl', dispaly: true, filter: true },
    { title: '日期', width: 120, sorter: true, render: data => datetime.format(data.Riqi, "yyyy-MM-dd"), key: 'Riqi', dispaly: true, filter: true },
    { title: '起息日', width: 120, sorter: true, render: data => datetime.format(data.Qxr, "yyyy-MM-dd"), key: 'Qxr', dispaly: true, filter: true },
    { title: '到期日', width: 120, sorter: true, render: data => datetime.format(data.Dqr, "yyyy-MM-dd"), key: 'Dqr', dispaly: true, filter: true },
    { title: '结算金额', className: 'column-money', render: data => com.formatNumber(data.Jsje), key: 'Jsje', width: 180, sorter: true, dispaly: true, filter: true },
    { title: '余额', className: 'column-money', render: data => com.formatNumber(data.Ye), key: 'Ye', width: 180, sorter: true, dispaly: true, filter: true },
    { title: '利率', dataIndex: 'Ll', key: 'Ll', width: 180, sorter: true, dispaly: true, filter: true },
];
const controls = [
    { name: 'Gslb', required: true, type: 'text', label: '归属类别', grid: 12 / 24 },
    { name: 'Khzh', required: true, type: 'text', label: '客户账号', grid: 12 / 24 },
    { name: 'Htbh', required: true, type: 'text', label: '合同编号', grid: 12 / 24 },
    { name: 'Htmc', required: true, type: 'text', label: '合同名称', grid: 12 / 24 },
    { name: 'Lccpdm', required: true, type: 'text', label: '理财产品代码', grid: 12 / 24 },
    { name: 'Lccpmc', required: true, type: 'text', label: '理财产品名称', grid: 12 / 24 },
    { name: 'Jydskhx', required: true, type: 'text', label: '交易对手开户行', grid: 12 / 24 },
    { name: 'Jydskhzh', required: true, type: 'text', label: '交易对手开户账号', grid: 12 / 24 },
    { name: 'Jydskhmc', required: true, type: 'text', label: '交易对手开户名称', grid: 12 / 24 },
    { name: 'Jydsdezf', required: true, type: 'text', label: '交易对手大额支付系统行号', grid: 12 / 24 },
    { name: 'Khjl', required: true, type: 'text', label: '客户经理', grid: 12 / 24 },
    { name: 'Jsje', required: true, type: 'alphanum', label: '结算金额', grid: 12 / 24 },
    { name: 'Ye', required: true, type: 'alphanum', label: '余额', grid: 12 / 24 },
    { name: 'Ll', required: true, type: 'alphanum', label: '利率', grid: 12 / 24 },
    { name: 'Riqi', required: true, type: 'text', label: '日期', min: 2, max: 30, grid: 12 / 24 },
    { name: 'Qxr', required: true, type: 'text', label: '起息日', min: 2, max: 30, grid: 12 / 24 },
    { name: 'Dqr', required: true, type: 'text', label: '到期日', min: 2, max: 30, grid: 12 / 24 },
]
const DataTable = dataTableCreate(daoName);
class QDTYXMS extends Component {
    constructor(props) {
        super(props);
        this.state = {
            dataChange: false
        };
    }
    componentDidMount() {
        this.props.dispatch({
            type: `${daoName}/setKeyName`,
            payload: { keyName: "ID" }
        });
        this.props.dispatch({
            type: `${daoName}/fetch`,
            payload: { daoName, page: 1, pageSize: 20 }
        });
        this.loadOptionData();
    }
    loadOptionData() {
        let options = []
        controls.map(c => {
            if (c.fetch) {
                let f = c.fetch;
                if (c.type === 'cascader-select') {
                    f.isCascader = true;
                }
                if (c.type !== 'search') {
                    options.push(f);
                }
            }
        })
        if (daoName && options.length > 0) {
            this.props.dispatch({ type: `${daoName}/fetchOptions`, payload: { options } });
        }
    }
    showModelHandler(isAdd) {
        let key = null
        if (!isAdd) {
            const len = this.props.selectedRowKeys.length;
            if (len === 0) {
                message.info('请选择要编辑的行，如果选择了多行，则使用最后一次选择！');
                return;
            }
            key = this.props.selectedRowKeys[len - 1]
        }
        this.props.dispatch({
            type: `${daoName}/openEdit`,
            payload: { key }
        });
    }
    hideEditHandler() {
        if (this.state.dataChange) {
            this.props.dispatch({
                type: `${daoName}/reload`,
                payload: { daoName },
            });
            this.state.dataChange = false;
        }
        this.props.dispatch({
            type: `${daoName}/hideEdit`
        });
    };


    render() {
        let { showEdit, record } = this.props
        return (
            <div className={styles.normal} style={{ background: '#fff', marginTop: -16, padding: '5px 5px' }}>
                <div>
                    <div className={styles.create}>
                        <ButtonGroup style={{ zIndex: 0 }}>
                            <Button onClick={this.showModelHandler.bind(this, false)}>业绩认定</Button>
                        </ButtonGroup>
                    </div>
                    <Modal title={record.Htbh + "业绩分配"} width={700} visible={showEdit} onCancel={this.hideEditHandler.bind(this)}>
                        <YJRDS ywid={record.ID} />
                    </Modal>
                    <DataTable ref="userTable" daoName={daoName} columns={columns} controls={controls} />
                </div>
            </div>
        )
    }
}
function mapStateToProps(state) {
    const { showEdit, record, selectedRowKeys, keyName } = state[daoName];
    return {
        showEdit,
        selectedRowKeys,
        keyName,
        record
    }
}
QDTYXMS = connect(mapStateToProps)(QDTYXMS)
export default QDTYXMS;
let render = (props) => React.createElement(QDTYXMS, props);

let f = new Factory()
f.set("QDTYXMS", render)
